package sys.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import sys.service.TbUserService;
import sys.core.annotation.LoginRequired;
import sys.core.annotation.RecordLog;
import sys.entity.PageData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import sys.entity.TbUserEntity;

import java.util.List;

@RestController
@Api(tags = "tbUser接口")
@RequestMapping("/tbUser")
public class TbUserController {


    private final TbUserService service;

    @Autowired
    public TbUserController(TbUserService service) {
        this.service = service;
    }

    /**
     * 查询
     *
     * @return
     */
    @ApiOperation(value = "查询")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/select")
    public List<TbUserEntity> select(@RequestBody TbUserEntity entity) {
        return service.select(entity);
    }

    /**
     * 模糊查询
     *
     * @return
     */
    @ApiOperation(value = "模糊查询")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/likeSelect")
    public PageData<TbUserEntity> likeSelect(@RequestBody TbUserEntity entity) {
        return service.likeSelect(entity);
    }

    /**
     * 更新
     *
     * @return
     */
    @ApiOperation(value = "更新")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/update")
    public void update(@RequestBody TbUserEntity entity) {
        service.update(entity);
    }

    /**
     * 添加
     *
     * @return
     */
    @ApiOperation(value = "添加")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/add")
    public void add(@RequestBody TbUserEntity entity) {
        service.add(entity);
    }

    /**
     * 删除
     *
     * @return
     */
    @ApiOperation(value = "删除")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/delete")
    public void delete(@RequestBody TbUserEntity entity) {
        service.delete(entity);
    }

    /**
     * 导出excel
     *
     * @return
     */
    @ApiOperation(value = "导出excel")
    @LoginRequired
    @RecordLog
    @GetMapping("/exportExcel")
    public void exportExcel(TbUserEntity entity, HttpServletResponse response) {
        service.exportExcel(entity, response);
    }

}
